package com.product;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.CategroryDao;
import com.dao.ProductDao;
import com.vo.Category;
import com.vo.Product;

public class IndexProductServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		ProductDao dao = new ProductDao();
		CategroryDao dao2 = new CategroryDao();
		int page =1,pageCount =0;
		List<Product> list = null;
		List<Category> list2 = null;
		try {
			list = dao.getAllDate();
			pageCount = dao2.getCount();
			list2 = dao2.getProduct(page, pageCount);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		HttpSession session = request.getSession();
		session.setAttribute("allProduct", list);
		session.setAttribute("productClass", list2);
		
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
